<%@ page import="com.hrpmar.service.LoginService" %>
<%@ page import="com.hrpmar.service.impl.LoginServiceImpl" %>
<%@ page import="com.hrpmar.utils.Constants" %>
<%@ page import="com.hrpmar.pojo.Worker" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: c
  Date: 2017-11-07
  Time: 17:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>艾尔菲HRP管理系统登陆</title>
    <link rel="stylesheet" href="${ctx}/statics/moban/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${ctx}/statics/moban/css/login.css" />
</head>
<body onkeydown="keyLogin()"  style="background: url(${ctx}/res/images/bg.jpg)">
<div class="beg-login-box">
    <header>
        <h1 style="color: black;">欢迎登录</h1>
    </header>
    <%
        Cookie[] cookies = request.getCookies();
        String name = null;
        String pwd = null;
        Integer id = null;
        if(cookies!=null) {
            for (int i = 0; i < cookies.length; i++) {
                if (cookies[i].getName().equals("name")) {
                    name = cookies[i].getValue();
                }
                if (cookies[i].getName().equals("pwd")) {
                    pwd = cookies[i].getValue();
                }
                if (cookies[i].getName().equals("id")) {
                    id = Integer.parseInt(cookies[i].getValue());
                }
            }
        }
    %>
    <div class="beg-login-main">
        <form action="" class="layui-form" method="post">

            <!---->
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon"></i>
                </label>
                <select name="deId" id="deId">
                    <option value="1" >医院管理登录</option>
                    <option value="2" >科室部登录</option>
                    <option value="3" >药房部登录</option>
                    <option value="4" >采购部登录</option>
                </select>
            </div>
            <!---->

            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon"></i>
                </label>
                <input type="text" name="landCode" autocomplete="off" value="<%=name==null?"":name%>" placeholder="请输入登录名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon"></i>
                </label>
                <input type="password" name="landPwd" autocomplete="off"  placeholder="请输入密码" class="layui-input" value="<%=pwd==null?"":pwd%>">
            </div>
            <div class="layui-form-item">
                <div class="beg-clear err" style="color: red;">
                    ${msg}
                </div>
                <div class="beg-pull-left beg-login-remember">
                    <label>记住帐号？</label>
                    <input type="checkbox" name="rememberMe" value="true" lay-skin="switch" checked="false" title="记住帐号"><div class="layui-unselect layui-form-switch layui-form-onswitch"><i></i></div>
                </div>
                <div class="beg-pull-right">
                    <button type="button" onclick="login()" class="layui-btn layui-btn-primary submit" 	data-search-on-enter-key="true">
                        <i class="layui-icon"></i> 登录
                    </button>
                </div>

            </div>
        </form>
    </div>


</div>
<script src="${ctx}/statics/js/jquery-1.12.4.js"></script>
<script src="${ctx}/statics/js/bootstrap.js"></script>
<script type="text/javascript" src="${ctx}/statics/moban/plugins/layui/layui.js"></script>
<script>
    layui.use(['layer', 'form'], function() {

    });
    
    function keyLogin() {
        if (event.keyCode==13){
            login();
        }
    }

    function checkLogin(){
        $("input[name='landCode']").focus(function(){
            $("div.err").html("");
        });
        $("input[name='landPwd']").focus(function(){
            $("div.err").html("");
        });
    }

    function login() {
        checkLogin();
        var param = $("form").serialize();
        $.post("${ctx}/userlogin",param,function(msg){
            if(msg!=null&&msg!=""){
                $("div.err").html(msg);
                $("input[name='landPwd']").val("");
                return;
            }
            location.href = "${ctx}/index";
        },"text");
    }

    $(function(){
        if(${requestScope.aa==null}){
            $.post("${ctx}/login",null,function (msg) {
                if(msg=="true"){
                    location.href = "${ctx}/cook";
                }
            });
        }

        if(${requestScope.aa=="update"}){
            $("input[name='landPwd']").val("");
        }

        $("#deId").val("<%=id==null?1:id%>");
    })
</script>
</body>

</html>
